package com.justnow.offer;

/**
 * @author justnow
 * Created on 2020-09-05
 * Description
 *
 * 深入总结呀
 */
public class Haoweilai02 {
    public ListNode reverseList (ListNode head) {
        if (head.next == null)
            return head;
        // write code here
        ListNode pre = head.next, current = head.next.next;
        pre.next = null;
        while (current != null) {
            ListNode next = current.next;
            current.next = pre;
            pre = current;
            current = next;
        }
        ListNode newHead = new ListNode();
        newHead.next = pre;
        return newHead;
    }
}

class ListNode {
    int val;
    ListNode next = null;
}